package wordit.impl.boardwise;

import wordit.Game;
import wordit.Letter;
import wordit.ea.Genome;
import wordit.ea.GenomeFactory;

public class BoardwiseGenomeFactory implements GenomeFactory {

	private final Game game;

	public BoardwiseGenomeFactory(Game game) {
		this.game = game;
	}
	
	@Override
	public Genome createRandomGenome() {
		BoardGenome board = new BoardGenome(game.getNumOfRows(), game.getNumOfColumns());
		
		for (Letter l : game.getLetters()) {
			int row,col;
			
			do {
				row = (int) (Math.random() * game.getNumOfRows());
				col = (int) (Math.random() * game.getNumOfColumns());
			} while (board.getLetterAt(row,col)!=null);
			
			board.setLetterAt(row,col,l);
		}
		
		return board;
	}

}
